
<%-- 
    Document   : oEstrategico
    Created on : 10/04/2010, 03:05:56 PM
    Author     : LAPTOP01
--%>

<%@ page language="java"  pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://struts.apache.org/tags-bean"  prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="/tags/c" prefix="c"%>
<%@ include file="seguridad.jsp" %>
<%@ include file="acceso.jsp" %>
<script src="scripts/ajax.js" language="JavaScript"></script>


<html>
    <script LANGUAGE="JavaScript">
        function meta(codigo,idob,desc){
            var form = document.getElementById("PEIForm");
            form.codObj.value = codigo;
            form.descObj.value = desc;
            form.action="PEI.do?dispatch=listarMetaO&codObj="+codigo+"&idob="+idob+"&descObj="+desc;
            form.method="post";
            form.submit();
        }

        function oEspecifico(codigo,idob,desc){
            var form = document.getElementById("PEIForm");
            form.codObj.value = codigo;
            form.idObj.value = idob;
            form.descObj.value = desc;
            form.action="PEI.do?dispatch=listarOEspecifico&cod="+codigo+"&idob="+idob+"&desc="+desc;
            form.method="post";
            form.submit();
        }

        function editarT(num,desc,cod){
            var form = document.getElementById("PEIForm");
            document.getElementById("opcionObj").value=2;
            document.getElementById("descObj").value=desc;
            document.getElementById("idObj").value=num;
            form.codObj.value = cod;
            document.getElementById("contador").value=desc.length;
        }

        function contar(texto,e){

            document.getElementById("contador").value=document.getElementById("descObj").value.length;

            if (texto.length >= 500 ) {
                if (navigator.appName == "Netscape") tecla = e.which
                else tecla = e.keyCode
                if (tecla != 8) return false
            }
            return true

        }

        function eliminar(codigo){
            if (confirmAction()==false) return;
            var desc = "";
            var idObj = 0;
            var idDiv = "divTabla";
            var metodo = "GET";
            var tipo = 3;
            var url = "consultasAjax/listarObjetivosAjax.jsp?desc="+desc+"&codigo="+codigo+"&tipo="+tipo+"&idObj="+idObj;
            var cadenaSalida = "";
            var async = true;
            document.getElementById(idDiv).innerHTML;
            autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
        }


        function confirmAction(){
            if (confirm("Se borrara Objetivo Estrategico, Objetivo Especifico ,indicadores ,Actividades Permanentes ,Medio de Verificacion,  y componentes del registro seleccionado  \n ¿Esta seguro de continuar? "))
                return true;
            else return false;
        }

         function confirmActionGuardar(){
              if (confirm("Se Guardara los cambios hechos en la pantalla  \n ¿Esta seguro de continuar? "))
                return true;
            else
                return false;
        }


        function insertar(){

           if (confirmActionGuardar()==false) return;
            
            var tipo=document.getElementById("opcionObj").value;
            var idObj = document.getElementById("idObj").value;
            var codigo = document.getElementById("codObj").value;
            var desc = document.getElementById("descObj").value;
            //alert("desc"+desc);
            //alert("desc"+desc);
            var idDiv = "divTabla";
            var metodo = "GET";
            var url = "consultasAjax/listarObjetivosAjax.jsp?desc="+desc+"&codigo="+codigo+"&tipo="+tipo+"&idObj="+idObj;
            var cadenaSalida = "";
            var async = true;
            document.getElementById(idDiv).innerHTML;
            autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
            document.getElementById("opcionObj").value=1;
            document.getElementById("descObj").value="";
            document.getElementById("idObj").value="";
            document.getElementById("contador").value="0";
             
        }

        function validar(){

            if (document.getElementById("idObj").value==""){
                alert("Ingrese el número del Objetivo Estratégico");
                document.getElementById("idObj").focus();
                return;
            }
            if (document.getElementById("descObj").value==""){
                alert("Ingrese la Descripción del Objetivo Estratégico");
                document.getElementById("descObj").focus();
                return;
            }
            insertar();
        }


        function autoCompletarDiv(metodo,url,cadena,async,idDiv)
        {
            if( window.XMLHttpRequest )
                ajax = new XMLHttpRequest(); // No Internet Explorer
            else
                ajax = new ActiveXObject("Microsoft.XMLHTTP");
            ELEMENT_DIV = idDiv;
            ajax.onreadystatechange = funcionCallbackVerDiv;
            ajax.open( metodo, url, async);
            ajax.send(cadena);
        }

        function funcionCallbackVerDiv()
        {
            if( ajax.readyState == 4 )
            {
                if( ajax.status == 200 )
                { //alert(ajax.responseText);
                    document.getElementById(ELEMENT_DIV).innerHTML = ajax.responseText;
                }
            }
        }

        function posicioninicial(){
            document.getElementById("idObj").focus();
            document.getElementById("idObj").select();
            
        }

        function iniciar(){
            document.getElementById("idObj").value="";

        }


        function parejas(caracter, code){
 this.caracter = caracter;
 this.code = code;
}
var pares = new Array();
//pares[0] = new parejas("€", "&euro;");
//pares[1] = new parejas("á", "&aacute;");
pares[0] = new parejas("%", "%25");
pares[1] = new parejas("á", "&aacute;");


function htmlentities(txt) {
for (var i = 0, total = pares.length; i < total; i ++)
 txt = txt.replace(new RegExp(pares[i].caracter, "g"), pares[i].code)
 return txt;
}








    </script>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link type="text/css" rel="stylesheet" href="lib/css/Style_Font_Text.css" >
        <link type="text/css" rel="stylesheet" href="lib/css/Style_PageTable.css" >
        <title>JSP Page</title>
    </head>
    <body onload="iniciar()">
        <center>
            <h1 class="substylo">Objetivo General Estrat&eacute;gico</h1>
        </center>
        <br>
        <div style="overflow: auto; width:710px; height: 400px">
            <table>
                <tr>
                    <td>
                        <html:form action="PEI.do?dispatch=ingresarOEstrategico" styleId="PEIForm">
                            <html:hidden property="opcionObj" styleId="opcionObj" value="1"/>
                            <table class="TableIngreso">
                                <A NAME="superior"></A>
                                <tr>
                                    <td align="left" class="tdLeft">
                                        N&uacute;mero Objetivo
                                        General Estrat&eacute;gico :
                                    </td>
                                    <td align="left">
                                        <html:text  styleId="idObj" property="idObj" maxlength="5" styleClass="text"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" class="tdLeft">
                                        Ingresar Objetivo
                                        General Estrat&eacute;gico :
                                    </td>
                                    <td align="left">
                                        <html:textarea styleId="descObj" property="descObj"  rows="5" cols="50" 
                                                       onkeydown="return contar(this.value,event)"
                                                       onkeyup="return contar(this.value,event)" />
                                        <br>
                                        <input type="text" size="2" id="contador"  />
                                        <label style="color: #990033" >M&aacute;ximo 500 caracteres</label>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <input type="button" value="Grabar" onclick="validar()"/>
                                    </td>
                                </tr>
                            </table>
                            <br>
                            <br>
                            <% int i = 1;%>
                            <logic:present name="PEIForm" property="listaOEstrategico">
                                <div id="divTabla" >
                                    <table id="tabla1" align="right" class="userTable">
                                        <tr class="even" align="center">
                                            <th class="textoTR">N&uacute;mero</th>
                                            <th class="textoTR">Objetivo General Estrat&eacute;gico </th>
                                            <th class="textoTR">Editar</th>
                                            <th class="textoTR">Eliminar</th>
                                            <th class="textoTR">Meta</th>
                                            <th class="textoTR">Objetivos Espec&iacute;ficos</th>
                                        </tr>
                                        
                                        <logic:iterate name="PEIForm" property="listaOEstrategico" id="lista">
                                            <tr align="center">
                                                <td  align="center" >
                                                    <bean:write name="lista" property="NUM_IDOBJ"/>.
                                                </td>

                                                <td align="center" style="width:800px;text-align: left" >
                                                    <bean:write name="lista" property="TX_DESCOBJ"/>
                                                </td>


                                                <td  align="center" >
                                                    <img style="cursor:pointer" title="Editar" alt="Editar" border=0  src="images/b_edit.png" onclick="editarT('<c:out value="${lista.NUM_IDOBJ}"/>','<c:out value="${lista.TX_DESCOBJ}"/>','<c:out value="${lista.NUM_CODOBJ_PK}"/>');posicioninicial();"/>
                                                </td>

                                                <td  align="center" >
                                                    <img style="cursor:pointer" title="Eliminar" title="Eliminar" alt="Eliminar" border=0  src="images/b_drop.png" onclick="eliminar('<c:out value='${lista.NUM_CODOBJ_PK}'/>');">
                                                </td>

                                                <td  align="center" >
                                                    <img style="cursor:pointer" title="Meta" title="Meta" alt="Meta" border=0  src="images/file_preview.png" onclick = "meta('<c:out value='${lista.NUM_CODOBJ_PK}'/>','<c:out value='${lista.NUM_IDOBJ}'/>','<c:out value='${lista.TX_DESCOBJ}'/>');">
                                                </td>

                                                <td  align="center" >
                                                    <img style="cursor:pointer" title="Objetivo Especifico" title="Objetivo Especifico" alt="OEspecifico" border=0  src="images/file_preview.png" onclick="oEspecifico('<c:out value='${lista.NUM_CODOBJ_PK}'/>','<c:out value='${lista.NUM_IDOBJ}'/>','<c:out value='${lista.TX_DESCOBJ}'/>');">
                                                </td>
                                            </tr>
                                        </logic:iterate>
                                    </table>
                                </div>
                            </logic:present>
                            <html:hidden property="codObj" styleId="codObj"/>
                            <html:hidden property="descObj" styleId="descObj"/>
                        </html:form>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>